<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return=array();
	exi($return);
}
if($_RQ['op']=='uparea_dianid'){
	if($_RQ['id']){
		$this->model('member')->checklogin();
		pdo_update('jy_area_dian_member',array('dian_id'=>$_RQ['id']),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	}
	exi('更新成功！');
}
if($_RQ['op']=='uppcd'){
	$post=get_postdata();
	if($post['lat'] || $post['lng']){
		$lat_lng=array('lat'=>$post['lat'],'lng'=>$post['lng']);
		$_SESSION['lat_lng']=$lat_lng;
	}
	$_SESSION['pcd']=$post;
	exi('更新成功！');
}
//获取门店
if($_RQ['op']=='getdians'){
	$post=get_postdata();
	$dians = pdo_getall('jy_area_dian_agent',array('uniacid'=>$_SESSION['uniacid'],'status'=>1));
	if($post['lat_lng'] || $_RQ['lat']){
		$post['lat_lng']=$post['lat_lng']?:array('lat'=>$_RQ['lat'],'lng'=>$_RQ['lng']);
		foreach($dians as $k=>&$v){
			$v['lat_lng']=json_decode($v['lat_lng'],true);
			$v['pcd']= json_decode($v['pcd'],true);
			if($v['lat_lng']){				
				$v['distance']=cfc('tools')->getdistance($post['lat_lng']['lng'],$post['lat_lng']['lat'],$v['lat_lng']['lng'],$v['lat_lng']['lat']);
				$v['distance']=intval($v['distance']/1000);
			}
			if($post['juli'] && $v['distance']>$post['juli']){
				unset($dians[$k]);
			}
		}
		paixu($dians,'distance');
	}else{
		foreach($dians as $sv2){
			$sv2['pcd']= json_decode($sv2['pcd'],true);
		}
	}
	foreach($dians as $k=>$nv){
		if($nv['id']==$_SESSION['dian_id']){
			$newdian=$nv;
			unset($dians[$k]);
		}
	}
	if($newdian){
		array_unshift($dians,$newdian);
	}
	$return['dians_count']=count($dians);
	$return['dians']=$dians;
	exi($return);
}
?>